package com.igeekhome.controller.api;

import com.igeekhome.pojo.DNetwork;
import com.igeekhome.pojo.ScanCar;
import com.igeekhome.service.ICarService;
import com.igeekhome.util.ResultBean;
import com.igeekhome.util.TableResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * @author Romeo
 */
@RestController
@RequestMapping("/api/car")
public class CarControllerApi {
    @Autowired
    private ICarService carService;

    /**
     *
     *   # 最大净重/吨 MaxEight
     *   MAX_EIGHT = 500.00
     *   # 最大百公里耗油/千克 MaxAuthorized
     *   MAX_AUTHORIZED = 50.00
     *   # 最大核定载重/吨 MaxHundredFuel
     *   MAX_HUNDRED_FUEL = 450.00
     */
    @Value("${MAX_EIGHT}")
    private BigDecimal MAX_EIGHT;
    @Value("${MAX_AUTHORIZED}")
    private BigDecimal MAX_AUTHORIZED;
    @Value("${MAX_HUNDRED_FUEL}")
    private BigDecimal MAX_HUNDRED_FUEL;


    @RequestMapping("/list")
    public TableResultBean list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit){
        return carService.list(page, limit);
    }
    @RequestMapping("/add")
    public ResultBean add(ScanCar scanCar, HttpServletRequest request){
        DNetwork network = (DNetwork)request.getSession().getAttribute("network");
        Integer networkid = network.getNetworkId();
        return carService.add(scanCar,networkid,MAX_EIGHT,MAX_AUTHORIZED,MAX_HUNDRED_FUEL);
    }
    @RequestMapping("/edit")
    private ResultBean edit(ScanCar scanCar){
        return carService.edit(scanCar,MAX_EIGHT,MAX_AUTHORIZED,MAX_HUNDRED_FUEL);
    }
    @RequestMapping("/delete")
    private ResultBean delete(String idsStr){
        return carService.loginDelete(idsStr);
    }
}
